package com.xzmzhp.controller.maintain;

import cn.hutool.core.collection.CollUtil;
import com.xzmzhp.constant.ReturnConstant;
import com.xzmzhp.pojo.maintain.LendImgs;
import com.xzmzhp.service.maintain.LendImgsService;
import com.xzmzhp.utils.StringUtils;
import com.xzmzhp.utils.return_tool.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 王源(xm)
 * @create: 2022-04-24 18:46
 * @program: ams
 * @description: 借出记录图片前端交互类
 */
@Controller
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/lendImgs")
public class LendImgsController {
    @Autowired
    private LendImgsService lendImgsService;

    /**
     * 根据借出记录id查询数据
     * @param lendId 借出记录id
     * @return 借出记录图片信息
     */
    @GetMapping("/findLendImgsByLendId")
    public ReturnData findLendImgsByLendId(Integer lendId){
        List<LendImgs> list = lendImgsService.findLendImgsByLendId(lendId);
        if (CollUtil.isNotEmpty(list)){
            return ReturnData.ok(list);
        }
        return ReturnData.error(ReturnConstant.FAIL,"查询借出记录图片信息失败");
    }

    /**
     * 添加借出记录图片信息
     * @param lendImg 借出记录图片信息
     * @return 是否成功
     */
    @PostMapping("/addLendImg")
    public ReturnData addLendImgs(@RequestBody LendImgs lendImg){
        Integer i = lendImgsService.addLendImgs(lendImg);
        if (StringUtils.isNotNull(i)){
            return ReturnData.ok();
        }
        return ReturnData.error(ReturnConstant.FAIL,"添加借出记录图片信息失败");
    }

    /**
     * 批量添加借出记录图片信息
     * @param lendImgs 借出记录图片信息
     * @return 是否成功
     */
    @PostMapping("/addLendImgs")
    public ReturnData addLendImgs(@RequestBody List<LendImgs> lendImgs){
        Integer i = lendImgsService.addLendImgs(lendImgs);
        if (StringUtils.isNotNull(i)){
            return ReturnData.ok();
        }
        return ReturnData.error(ReturnConstant.FAIL,"批量添加借出记录图片信息失败");
    }

    /**
     * 修改借出记录图片信息
     * @param lendImgs 借出记录图片信息
     * @return 是否成功
     */
    @PostMapping("/exitLendImgs")
    public ReturnData exitLendImgs(LendImgs lendImgs){
        Integer i = lendImgsService.exitLendImgs(lendImgs);
        if (StringUtils.isNotNull(i)){
            return ReturnData.ok();
        }
        return ReturnData.error(ReturnConstant.FAIL,"修改借出记录图片信息失败");
    }

    /**
     * 删除借出记录图片信息
     * @param id 借出记录图片id
     * @return 是否成功
     */
    @PostMapping("/delLendImgs")
    public ReturnData delLendImgs(Integer id){
        Integer i = lendImgsService.delLendImgs(id);
        if (StringUtils.isNotNull(i)){
            return ReturnData.ok();
        }
        return ReturnData.error(ReturnConstant.FAIL,"删除借出记录图片信息失败");
    }

    /**
     * 根据财务id删除借出记录图片信息
     * @param lendId 借出记录图片信息id
     * @return 是否成功
     */
    @PostMapping("/delLendImgsByLendId")
    public ReturnData delLendImgsByLendId(Integer lendId){
        Integer i = lendImgsService.delLendImgsByLendId(lendId);
        if (StringUtils.isNotNull(i)){
            return ReturnData.ok();
        }
        return ReturnData.error(ReturnConstant.FAIL,"批量删除借出记录图片信息失败");
    }
}
